﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BBPA.Admin.Store.Goods
{
    public partial class List : ListPage
    {
        BLL.V_Goods bllList = new BLL.V_Goods();
        BLL.Goods bll = new BLL.Goods();
        //
        BLL.Pic bllPic = new BLL.Pic();
        BLL.Goods_BuyPrice_Log bllBuyPrice_Log = new BLL.Goods_BuyPrice_Log();
        BLL.Goods_SellPrice_Log bllSellPrice_Log = new BLL.Goods_SellPrice_Log();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string istopsearch = Request["istopsearch"] == null || Request["istopsearch"].ToString() == "" ? "0" : Request["istopsearch"].ToString();
                if (Convert.ToInt32(istopsearch) < 1)
                {
                    is_top_search.InnerHtml = "";
                }
                search_select_category.SelectedValue = DataTypePlus.requestString(Request.QueryString["search_select_category_tb_Category"]);
            }
            string sql_MeAdd = "select RowID from User_Operate_Log where UserID=" + Security.GetCurrentUserID() + " and TableName='" + EnumHelper.TableName.Goods + "' and OperateType=" + (int)EnumHelper.OperateType.Add + "";//本店添加的商品
            Master.BasicSQL = "(State=" + (int)EnumHelper.GoodsState.Nomal + " or (State=" + (int)EnumHelper.GoodsState.WaitCheck + " and id in(" + sql_MeAdd + ")))";
            Master.BasicSQL += " and IsOffShelf=0 and SupplierName is not null and State=" + (int)EnumHelper.GoodsState.Nomal;
        }
        public override void buildSQL_Page_List_search()
        {
            Master.SearchSQL = "";
            if (search_text_namenumber.Text != "")
                Master.SearchSQL = StringPlus.SQLand(Master.SearchSQL, " ( name like '%" + search_text_namenumber.Text + "%' or brandname like '%" + search_text_namenumber.Text + "%')"); ;
            if (search_select_brand.SelectedValue != "" && search_select_brand.SelectedValue != "0") 
                Master.SearchSQL = StringPlus.SQLand(Master.SearchSQL, "BrandID=" + search_select_brand.SelectedValue + "");
            if (search_select_category.SelectedValue != "" && search_select_category.SelectedValue != "0")
                Master.SearchSQL = StringPlus.SQLand(Master.SearchSQL, "'|'+CategoryID_Tree like '%|" + search_select_category.SelectedValue + "|%'");
            if (search_select_supplier.SelectedValue != "" && search_select_supplier.SelectedValue != "0")
                Master.SearchSQL = StringPlus.SQLand(Master.SearchSQL, "SupplierID=" + search_select_supplier.SelectedValue + "");
            if (search_check_sellway_1.Checked)
            {
                string sql_SellWay = " id in ";
                sql_SellWay += " (select GoodsID from Goods_SaleWay_Discount where  DiscountSell<100 and DateFrom<=getdate() and DateTo>=getdate() ) or";
                sql_SellWay += " id in ";
                sql_SellWay += " (select GoodsID from Goods_SaleWay_GiftNumber where  GiftNumberSell>0 and  DateFrom<=getdate() and DateTo>=getdate() ) ";
                Master.SearchSQL = StringPlus.SQLand(Master.SearchSQL, sql_SellWay);
            }
        }
        public override DataSet get_Page_DataSet(string sql_, string orderby_, int pageFrom_, int pageTo_) { return bllList.GetListByPage(sql_, orderby_, pageFrom_, pageTo_); }

        //protected void Button2_Click(object sender, EventArgs e)
        //{
        //    if (top_search_content.Text.Trim() != "") 
        //        Response.Redirect("List.aspx?namenumber=" + top_search_content.Text.Trim());
        //}

        //protected void btnTopSearch_Click(object sender, EventArgs e)
        //{
        //    if (txtTopSearch_Content.Text.Trim() != "") search_text_namenumber.Text = txtTopSearch_Content.Text;
        //    Master.SearchSQL = "";
        //    if (search_text_namenumber.Text != "")
        //        Master.SearchSQL = StringPlus.SQLand(Master.SearchSQL, " ( name like '%" + search_text_namenumber.Text + "%' or brandname like '%" + search_text_namenumber.Text + "%')"); ;
        //    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "page_build(''); ", true);
        //}
    }
}